import { ColumnGroupType, ColumnType } from "antd/es/table"

import Copy from "@/components/business/copy/Copy"
import { handleNumber, handleNumberColor } from "@/utils/util"

function formattedDate(dayString: string) {
	if (dayString) {
		const year = dayString.slice(0, 4)
		const month = dayString.slice(4, 6)
		const day = dayString.slice(6, 8)
		return `${year}-${month}-${day}`
	}
	return null
}

export const proxyIncomeRecordColumns = (
	newFormat: (p: { id: string } | string) => string,
	_getFromDic: (arg: string, strictlyLabel?: boolean) => any
): Record<string, ColumnGroupType<any> | ColumnType<any>> => ({
	proxyIncomeRecord_orderNo: {
		key: "orderNo",
		align: "center",
		dataIndex: "orderNo",
		title: newFormat("funds.order_no"),
		render: (text: string) => <Copy title={text} />,
		width: 280,
		fixed: true
	},
	proxyIncomeRecord_cycleEndDate: {
		key: "cycleEndDate",
		dataIndex: "endTime",
		title: newFormat("label.report.rebate_cycle"),
		align: "center",
		width: 120,
		fixed: false,
		render: (value: string) => <div>{value ? formattedDate(String(value)) : null}</div>
	},
	proxyIncomeRecord_proxyName: {
		key: "proxyName",
		dataIndex: "proxyName",
		width: 120,
		render: (text: string) => <Copy title={text} />,
		title: newFormat("label.agent_number"),
		align: "center",
		fixed: false
	},
	proxyIncomeRecord_businessModel: {
		key: "businessModel",
		dataIndex: "businessModel",
		title: newFormat("agent.business_model"),
		align: "center",
		width: 120,
		fixed: false,
		render: (_text: any, record: any) =>
			(() => {
				let contentToRender
				switch (record.businessModel) {
					case 0:
						contentToRender = <p>{newFormat("label.business_model_both")}</p>
						break
					case 1:
						contentToRender = <p>{newFormat("label.business_model_cash")}</p>
						break
					case 2:
						contentToRender = <p>{newFormat("label.business_model_credit")}</p>
						break
					default:
						contentToRender = <p>-</p>
				}
				return contentToRender
			})()
	},
	proxyIncomeRecord_incomeRate: {
		key: "incomerate",
		dataIndex: "incomerate",
		title: newFormat("funds.check_income"),
		align: "center",
		width: 120,
		fixed: false,
		render: () => <a>{newFormat("common.check")}</a>
	},
	proxyIncomeRecord_parentProxyName: {
		dataIndex: "parentProxyName",
		key: "parentProxyName",
		title: newFormat("agent.direct_superior"),
		align: "center",
		width: 200,
		render: (text: string) => <Copy title={text} />
	},
	proxyIncomeRecord_topProxyName: {
		dataIndex: "topProxyName",
		title: newFormat("title.topProxyName"),
		width: 120,
		align: "center",
		render: (text: string) => <Copy title={text} />
	},
	proxyIncomeRecord_dxServiceFeeRebateAmount: {
		key: "dxServiceFeeRebateAmount",
		dataIndex: "dxServiceFeeRebateAmount",
		title: newFormat("funds.service_fee_rebate_amount"),
		align: "center",
		width: 200,
		fixed: false,
		render: (value: number) => {
			return <span style={{ color: handleNumberColor(value) }}>{handleNumber("USDT", String(value), 2)} </span>
		}
	},
	proxyIncomeRecord_dxInsurancePartsAmount: {
		key: "dxInsurancePartsAmount",
		dataIndex: "dxInsurancePartsAmount",
		title: newFormat("funds.insurance_parts_amount"),
		align: "center",
		width: 200,
		fixed: false,
		render: (value: number) => {
			return <span style={{ color: handleNumberColor(value) }}>{handleNumber("USDT", String(value), 2)} </span>
		}
	},
	proxyIncomeRecord_valueAddedTotalAmount: {
		key: "valueAddedTotalAmount",
		dataIndex: "valueAddedTotalAmount",
		title: newFormat("funds.value_added_total_amount"),
		align: "center",
		width: 200,
		fixed: false,
		render: (value: number) => {
			return <span style={{ color: handleNumberColor(value) }}>{handleNumber("USDT", String(value), 2)} </span>
		}
	},
	proxyIncomeRecord_otherVenueRebateAmount: {
		key: "otherVenueRebateAmount",
		dataIndex: "otherVenueRebateAmount",
		title: newFormat("funds.other_venue_rebate_amount"),
		align: "center",
		width: 200,
		fixed: false,
		render: (value: number) => {
			return <span style={{ color: handleNumberColor(value) }}>{handleNumber("USDT", String(value), 2)} </span>
		}
	},
	proxyIncomeRecord_otherVenuePartsAmount: {
		key: "otherVenuePartsAmount",
		dataIndex: "otherVenuePartsAmount",
		title: newFormat("funds.other_venue_parts_amount"),
		align: "center",
		width: 200,
		fixed: false
	},
	proxyIncomeRecord_currentIncomeAmount: {
		key: "currentIncomeAmount",
		dataIndex: "currentIncomeAmount",
		title: newFormat("funds.fund_audit.current_period_revenue"),
		align: "center",
		width: 120,
		fixed: false,
		render: (value: number) => {
			return <span style={{ color: handleNumberColor(value) }}>{handleNumber("USDT", String(value), 2)} </span>
		}
	},
	proxyIncomeRecord_adjustIncomeAmount: {
		key: "adjustIncomeAmount",
		dataIndex: "adjustIncomeAmount",
		title: newFormat("funds.fund_audit.revenue_adjustment"),
		align: "center",
		width: 120,
		fixed: false,
		render: (value: number) => {
			return <span style={{ color: handleNumberColor(value) }}>{handleNumber("USDT", String(value), 2)} </span>
		}
	},
	proxyIncomeRecord_realIncomeAmount: {
		key: "realIncomeAmount",
		dataIndex: "realIncomeAmount",
		title: newFormat("funds.fund_audit.adjusted_revenue"),
		align: "center",
		width: 120,
		fixed: false,
		render: (value: number) => {
			return <span style={{ color: handleNumberColor(value) }}>{handleNumber("USDT", String(value), 2)} </span>
		}
	},
	proxyIncomeRecord_payoutTime: {
		key: "payoutTime",
		dataIndex: "payoutTime",
		title: newFormat("funds.proxy_member_funds_record.issue_time"),
		align: "center",
		width: 120,
		fixed: false
	},
	proxyIncomeRecord_audit1Desc: {
		key: "audit1Desc",
		dataIndex: "audit1Desc",
		title: newFormat("common.remarks"),
		align: "center",
		width: 120,
		fixed: false,
		render: (value: number, record: any) => {
			return (
				<div>
					<div>
						{newFormat("funds.audit1_Desc")}:{record.audit1Desc}
					</div>
					<div>
						{newFormat("funds.audit2_Desc")}:{record.audit2Desc}
					</div>
				</div>
			)
		}
	}
})
